package com.fan.analysis.module.analysis.group.controller;


import com.fan.analysis.common.constant.ResponseCodeConst;
import com.fan.analysis.common.domain.ResponseDTO;
import com.fan.analysis.module.analysis.group.domain.entity.GroupInfoEntity;
import com.fan.analysis.module.analysis.group.domain.vo.GroupInfoVo;
import com.fan.analysis.module.analysis.group.domain.vo.GroupVo;
import com.fan.analysis.module.analysis.group.domain.vo.KeyPersonInfoVo;
import com.fan.analysis.module.analysis.group.domain.vo.UserGroupVo;
import com.fan.analysis.module.analysis.group.service.UserGroupService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用户群体识别的控制器
 *
 * @author fan
 * @date 2021/09/23 20:58
 **/
@RestController
@Slf4j
public class UserGroupController {


    private final UserGroupService userGroupService;

    @Autowired
    public UserGroupController(UserGroupService userGroupService) {
        this.userGroupService = userGroupService;
    }

    @ApiOperation("数据分析-用户群体识别 @author fan")
    @PostMapping(value = "/analysis/get_user_group")
    @Cacheable(value = "dict", key = "#p0")
    public ResponseDTO<UserGroupVo> getUserGroup(@RequestParam("phone_num") String phoneNum) {
        log.info("数据分析-用户群体识别");
        try {
            return userGroupService.getNodeLinkGroupInfo(phoneNum);

        } catch (Exception exception) {
            log.info(exception.getMessage());
            return ResponseDTO.wrap(ResponseCodeConst.SYSTEM_ERROR);
        }
    }

    @ApiOperation("数据分析-用户常用联系人信息 @author fan")
    @PostMapping(value = "/analysis/get_key_person_info/{phone_num}")
    public ResponseDTO<KeyPersonInfoVo> getKeyPersonInfo(@PathVariable("phone_num") String phoneNum) {
        log.info("数据分析-用户常用联系人信息");
        try {
            return userGroupService.getKeyPersonInfo(phoneNum);
        } catch (Exception exception) {
            log.info(exception.getMessage());
            return ResponseDTO.wrap(ResponseCodeConst.SYSTEM_ERROR);
        }
    }

    @ApiOperation("数据分析-获取群体信息 @author fan")
    @PostMapping(value = "/analysis/get_group/{group_id}")
    public ResponseDTO<GroupInfoVo> getGroup(@PathVariable("group_id") String groupId) {

        log.info("数据分析-获取群体信息");
        try {
            return userGroupService.getGroup(groupId);
        } catch (Exception exception) {
            log.info(exception.getMessage());
            return ResponseDTO.wrap(ResponseCodeConst.SYSTEM_ERROR);
        }
    }

    @ApiOperation("数据分析-通过关键词获取群体信息 @author fan")
    @PostMapping(value = "/analysis/get_group_info")
    public ResponseDTO<List<GroupVo>> getGroupInfo(@RequestParam("group_keyword") String groupKeyword) {

        log.info("数据分析-通过关键词获取群体信息，关键词为：" + groupKeyword);
        try {
            return userGroupService.getGroupInfo(groupKeyword);
        } catch (Exception exception) {
            log.info(exception.getMessage());
            return ResponseDTO.wrap(ResponseCodeConst.SYSTEM_ERROR);
        }
    }



}
